/*
 * @Author: szx
 * @Date: 2022-04-05 13:40:01
 * @LastEditTime: 2022-04-05 14:00:05
 * @Description:
 * @FilePath: \leetcode\剑指offerII\035\035.js
 */
/**
 * @param {string[]} timePoints
 * @return {number}
 */
var findMinDifference = function (timePoints) {
    const time = timePoints.map((v) => v.split(':').map((v) => parseInt(v)));
    time.sort((a, b) => {
        if (a[0] == b[0]) return a[1] - b[1];
        else return a[0] - b[0];
    });
    time.push([time[0][0] + 24, time[0][1]]);
    let min = Infinity;
    console.log(time);
    for (let i = 1; i < time.length; i++) {
        let tmp = (time[i][0] - time[i - 1][0]) * 60;
        tmp += time[i][1] - time[i - 1][1];
        if (min > tmp) min = tmp;
    }
    return min;
};

var findMinDifference = function (timePoints) {
    const time = timePoints.map((v) => {
        const arr = v.split(':');
        return arr[0] * 60 + parseInt(arr[1]);
    });
    time.sort((a, b) => a - b);
    time.push(60 * 24 + time[0]);
    let min = Infinity;
    let tmp = 0;
    for (let i = 1; i < time.length; i++) {
        tmp = time[i] - time[i - 1];
        if (min > tmp) min = tmp;
    }
    return min;
};
console.log(findMinDifference(['23:59', '00:00']));
